package com.esri.core.tasks.ags.geoprocessing;

import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.UserCredentials;
import com.esri.core.tasks.ags.geoprocessing.GPJobResource;
import java.util.ArrayList;

/* loaded from: classes.dex */
class GPSubmitJobAndPollTaskWithResults extends GPSubmitJobAndPollTaskCore<GPJobResults> {
    private static final long serialVersionUID = 1;

    public GPSubmitJobAndPollTaskWithResults(GPTaskParameters gPTaskParameters, String str, UserCredentials userCredentials) {
        super(gPTaskParameters, str, userCredentials);
    }

    public GPSubmitJobAndPollTaskWithResults(GPTaskParameters gPTaskParameters, String str, UserCredentials userCredentials, TaskListener<GPJobResults> taskListener) {
        super(gPTaskParameters, str, userCredentials, taskListener);
    }

    @Override // com.esri.core.internal.tasks.a
    public GPJobResults execute() throws Exception {
        GPJobResource execInternal = execInternal(true);
        GPTaskParameters gPTaskParameters = (GPTaskParameters) getActionInput();
        ArrayList arrayList = new ArrayList();
        if (execInternal.getJobStatus() == GPJobResource.JobStatus.SUCCEEDED) {
            String[] outputDataParamNames = gPTaskParameters.getOutputDataParamNames();
            String[] outputImageParamNames = gPTaskParameters.getOutputImageParamNames();
            if (outputDataParamNames != null) {
                for (String str : outputDataParamNames) {
                    arrayList.add(getResultData(execInternal, str));
                }
            }
            if (outputImageParamNames != null) {
                for (String str2 : outputImageParamNames) {
                    arrayList.add(getResultImage(execInternal, str2));
                }
            }
        }
        return new GPJobResults(execInternal, (GPParameter[]) arrayList.toArray(new GPParameter[0]));
    }

    private GPParameter getResultImage(GPJobResource gPJobResource, String str) throws Exception {
        return new GPGetJobResultTask(new GPGetJobResultParameters(gPJobResource, str, true), this.serviceURL, this.credentials).execute();
    }

    private GPParameter getResultData(GPJobResource gPJobResource, String str) throws Exception {
        return new GPGetJobResultTask(new GPGetJobResultParameters(gPJobResource, str, false), this.serviceURL, this.credentials).execute();
    }
}
